import React from 'react';
import ModalForm from '../../../components/modalForm';
import { phoneRule, requiredRule } from '../../../utils/index';

export default function Editor(props) {
    const { isNew, editorData: { empId, employee, mobile} } = props;
    let config = {};
    if (!isNew && !empId) {
        return;
    }
    if (!isNew) {
        config.empId = {
            label: 'ID',
            fd: {
                initialValue: empId,
            },
            input: {
                disabled: true,
            },
        };
    } else {
        config.userName = {
            label: '用户名',
            input: {
                placeholder: '请设置用户名, 登录时使用',
            },
            fd: {
                rules: [requiredRule],
            },
        };
        config.password = {
            label: '密码',
            input: {
                type: 'password',
                placeholder: '请设置密码',
            },
            fd: {
                rules: [requiredRule],
            },
        };
    }
    config = {
        ...config,
        employee: {
            label: '姓名',
            input: {
                placeholder: '请输入员工姓名',
            },
            fd: {
                rules: [requiredRule],
                initialValue: employee,
            },
        },
        mobile: {
            label: '手机号',
            input: {
                placeholder: '请输入手机号或固话',
            },
            fd: {
                rules: [phoneRule, requiredRule],
                initialValue: mobile,
            },
            status: {
                label: '状态',
                type: 'bool',
            },
        },
    };

    return (
        <ModalForm
            {
                ...{
                    ...props,
                    config,
                }
            }
        />
    );
}
